#include<stdio.h>

int main()
{
    FILE* myfile = fopen("./hello.txt","w");
    if(myfile == NULL)
    {
        perror("fopen false");
        fclose(myfile);
        return 0;
    }


    //fwrite
    char arr[] = "linux so easy";
    int count = sizeof(arr)/sizeof(arr[0]);
    size_t wsz = fwrite(arr,1,count,myfile);
    if(wsz != count)
        printf("写入错误");
    fclose(myfile);


    //printf("arr size : %d\n",count);
////////////////////////////////////////////////////////
    FILE* myrfile = fopen("./bite.txt","r");
    if(myrfile == NULL)
    {
        perror("fopen false");
        fclose(myfile);
        return 0;
    }
    //fread
    char carr[20];
    size_t  rsz = fread(carr,sizeof(char),20,myrfile);
    printf("%s\n",carr);


    //seek

    // 移动到文件开头的第0个字节
    if(fseek(myrfile,0,SEEK_SET) != 0)
    {
        perror("fseek false");
        fclose(myrfile);
        return 0;
    }
    long fsz = ftell(myrfile);
    printf("file size %ld\n",fsz);
    fclose(myrfile);
    
    return 0;
}